package fi.referencefatory.childphone;

import android.app.LauncherActivity.ListItem;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;

public class ContactItem extends ListItem implements Parcelable {
	private Bitmap mAvatar;
	private String mName = null;
	private String mNumber = null;
	
	private boolean mSelected;
	
	public ContactItem() {
	}
	
	public ContactItem(ContactItem source) {
		Log.d("ContactItem", "ContactItem");
		if (source != null) {
			this.mAvatar = source.mAvatar; // shallow, deep copy needed?
			this.mName = source.mName;
			this.mNumber = source.mNumber;
		}
	}
	
	
	public ContactItem(Parcel in) {
		this.mAvatar = in.readParcelable(Bitmap.class.getClassLoader());
		this.mName = in.readString();
		this.mNumber = in.readString();
	}
	
	@Override
	public void writeToParcel(Parcel out, int flags) {
		out.writeString(mName);
		out.writeString(mNumber);
		if (mAvatar != null) {
			out.writeValue(true);
			out.writeParcelable(mAvatar, PARCELABLE_WRITE_RETURN_VALUE);
		} else {
			out.writeValue(false);
		}
	}
	
	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public static final Parcelable.Creator<ContactItem> CREATOR
		    = new Parcelable.Creator<ContactItem>() {
		public ContactItem createFromParcel(Parcel in) {
		    return new ContactItem(in);
		}
		
		public ContactItem[] newArray(int size) {
		    return new ContactItem[size];
		}
	};
	
	public void setName(String name) {
		mName = name;
	}
	
	public void setNumber(String number) {
		mNumber = number;
	}
	
	public void setAvatarBitmap(Bitmap avatar) {
		mAvatar = avatar;
	}
	
	public String getName() {
		return mName;
	}
	
	public String getNumber() {
		return mNumber;
	}
	
	public Bitmap getAvatarBitmap() {
		return mAvatar;
	}

	public boolean isSelected() {
		return mSelected;
	}

	public void setSelected(boolean mSelected) {
		this.mSelected = mSelected;
	}
}
